package com.wedata.致远接口;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 13670279423
 *     Aa@123456
 */
public class 人员管理 {

    public static void main(String[] args) {
        getMembersByName("张杨");
        //getMembersByDept();
        //updateMember();
        //getAllMembers();
    }

    public static void getMembersByName(String name){
        JSONArray members = HttpUtils.getList(token.hostUrl + "/rest/orgMembers/name/"+name+"?token="+token.getToken());
        for(int i=0;i<members.size();i++){
            JSONObject member = members.getJSONObject(i);
            System.out.println(member);
        }
        //{"orgAccountId":670869647114347,"id":-5332376560213472597,"name":"杨林","code":"","createTime":1688095772450,"updateTime":1706687096277,"sortId":318,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"orgLevelId":-53080824737281993,"orgPostId":-6481062120812035580,"orgDepartmentId":-1625854415707355017,"type":1,"isInternal":true,"isLoginable":true,"isVirtual":false,"isAssigned":true,"isAdmin":false,"isValid":true,"state":1,"properties":{"birthday":"","politics":-1,"website":"","address":"","imageid":"","gender":-1,"degree":"","postAddress":"","emailaddress":"","reporter":"","blog":"","hiredate":"","extPostLevel":"","weixin":"","weibo":"","telnumber":"13670279423","postalcode":"","eduBack":-1,"officenumber":"","location":"","idnum":""},"second_post":[],"concurrent_post":[],"customerAddressBooklist":[],"pinyin":"yanglin","pinyinhead":"yl","address":"","location":"","valid":true,"isAssignedStatus":1,"fullName":"杨林","telNumber":"13670279423","loginName":"13670279423","entityType":"Member","emailAddress":"","defaultGuest":false,"idNum":"","postAddress":"","weixin":"","officeNum":"","weibo":"","degree":"","blog":"","visitor":false,"website":"","gender":-1,"v5External":false,"postalcode":"","vjoinExternal":false,"guest":false,"screenGuest":false,"i18nNameWithLocale":"杨林","dataI18nCategoryName":"organization.member.name","realSortId":318,"preName":"","orgAccountName":"健萌体育产业发展集团有限公司","orgPostName":"JAVA组长","orgDepartmentName":"财务信息化研发组","orgLevelName":"一般管理人员"}
    }

    /**
     * 查询部门下的所有员工
     */
    public static void getMembersByDept() {
        //减脂营：String strss = "241,-6461949825738259201;242,3645857095611338544;243,2567345472566021840;244,5434920947663588730;250,5726161211263045035;251,-6362660323123968658;252,2865501124121415241;253,1267291960764353100;254,-2379530924908983831";
        //健萌健身--旗下所有人员
        String strss = "-8096993078565190669,6323359022354418235,-7131292704168523341,6833688993602489260,-79406182635713077,-7719493163246728938,-4010910519786451256,-997332835278304848,-7390239711548519225,6030746595544352681,-111826641788777964,-959767415204854265,4406486300317405142,-8034245301373287429,-7380501259114492197,-3240023329079672147,-1879354062033170613,3006095454616242057,5810805159178292318,6421122408724123554,7672327409373627482,-6665774287823814644,-1688832286592055715,472202712197382272,-8595708329426138968,8662822035066276237,2573005958381914685,-8402116104027615397,-5092665155637129607,-6428121006271607174,2262177604199206652,-4488820566149673804,655477585032006129,489151603324961473,-8483293242629140675,2482942153275887272,4606612723426675220,-4915375036926901895,5172654741345356324,2152447501247924683,4284040632009376133,5717371342963623959,4488335458462550889,-2221499708550592794,-2776528345739214186,509564465085304342,-6046740410652081166,-8303767926524589162,7951423852081203020,3328834071567878592,-4845600396943733070,2920876134896453250,-3720967573209462492,4174356728003972443,3786417300418282993,2426493939644515343,-8135647391367541262,-3329321312362148477,-8273234361972407091,-4465061735987982726,5511597074724113116,4033898470969524224,-2355325717794635326,-1190834953025075463,2274629907201215742,-5164707585319680988,-8237543706978663451,-140380817321145390,-38571411908573401,6520364746358080412,6659983830124283021,-537652213579168083,-8427971559107637494,-8405011280187078322,-1605875681641086186,7690390609963597910,-255289218258418886,-3939011242926060693,-7668706279273314136,-2625868581413305370,-963622964344174983,-8448654173378293788,2794001022764925774,-8415926371843686029,1548257060979428794,-2764594001423219384,-1794476895381797208,4096228783953756664,3538773169380675494,-3674501646652849746,3615895684937762147,-4129207554570173676,727570858794307037,4215584909459408537,-9058672818453328819,7607422464304366082,-1730212786548423930,8700839058796070428,5742308948887159800,3501722695676871495,-2589134444077104092,-2395556100129013720,3521169486808501206,-7381176993207335815,2610487516953135653,6071235130516588141";

        List<String> phoneExt = Arrays.asList("13047209537","13142224050","13207471312","13258239331","13407174575","13549656843","13627336166","13755107932","13873057144","13873069144","13873723299","13875914934","13974953965","13975196946","14786400862","15079519537","15107475294","15111197964","15111311435","15116229370","15200829642","15200906907","15211015360","15243650698","15295954331","15526476849","15574940427","15576651961","15600928097","15618275663","15674873461","15773123347","15773395337","15802598283","15802646322","15907288790","15974191782","16670101046","16673152437","16673996155","17261403042","17343701200","17600423737","17630836483","17642501351","17673181093","17721541875","17773700085","17789653509","17839377836","17887972011","17889985756","18163782383","18163989250","18207489608","18229635199","18229985140","18274406672","18508477117","18511603154","18570069886","18573071724","18573243484","18670050976","18670766018","18670880917","18673129163","18673187170","18674821581","18684842303","18711129103","18722832689","18739022004","18774969941","18807300097","18807425974","18824155152","18826569601","18874285605","18874935562","18890325530","18890380100","18932411323","18973008118","18974005323","19118941212","19183378180","19376883666","19573140451","19896252423");

        String[] strs = strss.split(",");
        StringBuffer phones = new StringBuffer();
        StringBuffer names = new StringBuffer();
        for (String param : strs){

            JSONArray depts = HttpUtils.getList(token.hostUrl + "/rest/orgMembers/department/"+param+"?token="+token.getToken());


            //System.out.println(depts.size());
            for(int i=0;i<depts.size();i++){
                JSONObject member = depts.getJSONObject(i);
                //System.out.println(member);
                //System.out.println(member.getStr("name")+"    "+member.getStr("telNumber")+"    "+param[0]+"    "+member.getStr("id"));
                phones.append("'").append(member.getStr("telNumber")).append("',");
                names.append("('").append(member.getStr("telNumber")).append("',").append("'").append(member.getStr("name")).append("'),");
                if(phoneExt.contains(member.getStr("telNumber"))){
                    System.out.println("update wedata_company_employee_info set seeyon_id="+member.getStr("id")+" where phone='" + member.getStr("telNumber")+"' and name='"+member.getStr("name")+"';");
                }

            }

        }
        System.out.println(phones);
        System.out.println(names);
    }
    /**
     * 查询单位下的所有员工
     */
    public static void getAllMembers() {
        JSONArray members = HttpUtils.getList(token.hostUrl + "/rest/orgMembers/"+token.accountId+"?token="+token.getToken());

        List<String> phoneExt = Arrays.asList("15890074769","13755107932","17721541875","15101089787","15307365233","16670198804","18612192826","18670785122","18874276744","15388044116","18636861653","18510061358","17611433635","13017380703","13786163620","18774062015","17681771139","13787955486","17378271969","17700220908","18900789126","18173119288","18684688729","13771525277","18216307585","15111227443","17674504356","18169320888","13017380794","18570949556","15239323993","19898865527","18684568697","17608492223","19974838317","18163910007","19898829508","15055077344","18374960383","17352775567","18810182501","18874886126","15974151277","15822573190","13036782494","15616888637","15115620364","17879553511","18310704416","13142249733","13142181275","18173973009","15388040562","13627465920","18273128879","18675578709","13021808890","18670208418","18975910007","17670743822","18874714025","18474135071","19073135130","15399962022","16689531109","18608464641","15386433356","17773944609","18173704511","15673107219","15170135120","15111177036","18684953242","18588733724","15700776438","17871978873","13309472308","18673129163","15618275663","15111197964","18874285605","15773123347","18670766018","18674821581","15079519537","13627336166","15116229370","18807300097","18573071724","18207489608","15200829642","16670101046","18274406672","18973008118","13407174575","15111311435","18974005323","15211015360","18163989250","15200906907","17600423737","17343701200","17630836483","15295954331","18932411323","18673187170","18890325530","15674873461","13975196946","18229985140","19118941212","18570069886","13974953965","15574940427","15526476849","13875914934","13873723299","13549656843","16673152437","13873057144","16673996155","18824155152","18670050976","13047209537","18874935562","17889985756","18573243484","18826569601","15907288790","15600928097","15974191782","15773395337","13142224050","18684842303","17773700085","18711129103","13873069144","13258239331","13207471312","18508477117","18774969941","18670880917","15802598283","15802646322","14786400862","19376883666","15576651961","18890380100","18739022004","17642501351","15243650698","18163782383","18807425974","18229635199","16607005964","17673127904","13974819412","15886446615","15084701730","18890340897","15024709987","18846074613","15197505226","15399720748","15173885123","19512482144","15277807305","18768668294","18390958969","18608400849","15675182476","18699233219","18874117607","18173131206","13764411004","15575923035","17673841894","18073133057","18675411338","18916273296","18580394367","18554186308","18042663537","13467347307","18874048497","13787259121","13298612236","15111082946","18908407101","13787781273","17695687502","19974888795","18867214209","19189558743","15575909662","18673167013","13787224002","18275286176","18229951329","13787039125","18684800816","18673180901","18670010540","19015850590","13278865155","18682248796","13637312005","13787147942","18285998057","18774975821","15580375102","17376596959","15801948553","13667121663","13022502311","18670059727","13667309662","18182150563","18216181093","18238648360","18707331636","15652393132","15200877093","18601139800","17673451891","18975453976","18601604707","18221076397","15856872921","18692832649","18173682970","18942559988","15207489395","17673041081","18692845317","18269452272","13341311398","17363307355","17873547115","17873560853","18627336433","13816864269","15274906351","15581642109","13279255068","15765527439","18008408952","13207135523","15927667320","15623187785","18374989540","19173266507","18576724769","15377490094","15580078685","13302036613","15574353712","18274860835","15768988681","15115425073","18273621395","13527399958","15364086844","15111009037","18774881311","19386965332","15882117601","19311639893","13574417420","19898892390","18108434304","15101744550","17871996962","13909823976","15674945309","13787022045","15693176838","13145239374","15111067709","15873182141","15708927187","15580642065","18396590255","18311707636","13121201108","15105185263","18908478036","18673102403","18973676181","18975399784","19174188410","15517087387","15580013090","17521745605","18163634003","18390932030","15116615024","17873168317","13007301476","17512080525","13202071805","17891039503","18707399504","18397729783","16638236402","17318533927","18692730672","15102099567","13203056913","13027314016","17352866647","18229801703","17776526680","15575847044","13787196145","18684608997","18670863994","13786153979","17390019259","18570609690","15616030026","15348312233","13667932080","18975145848","13787084735","13716363903","15574860411","13107417167","18600601787","18602878719","18232659856","15344413111","13923731130","18670081895","18810777647","18374859915","15074962198","19174964485","13517499133","18670029727","13875017551","13203092046","13670279423","13007439030","18152632173","13973128491","13649251462","19174818095","18620366414","15650773509","18711057702","13117512143","18508428598","18846170431","15802621339","15200479227","18209916201","18673222284","15801696217","17725020743","13548724569","15581614696","18774096796","18711158412","15084971593","15273132129","18874752416","13975110777","18810339332","15973178862","18175847060","13508498371","18971019250","18573366050","17511687657","15581660680","18692850001","15874455411","15116418236","13974823782","18692946673","18229862562","18861872138","18207490394","17773350341","18216151939","18670022520","15900676392","15580878430","19884167950","18962612734","13272077304","18508458127","19386658740","18890040135","18692040276","15111308607","17520145619","18321912079","13874983431","18373054471","18163631562","18605996290","17610863629","15274802014","18515359570","15201732216","18574730426","18873242029","15200902536","18390809837","18229926420","15200856277","15174363715","18670715634","15173404347","18274957162","18773112435","13574128351","18846822295","18670429895","17873522110","15802537789","18378861733","18874042845","18820986930","15111488057","18890333757","18673123033","13627310216","15385555620","18373161139","13548711463","17373240604","17674107108","13290782343","15243800780","13290053690","13349884449","18627567546","18500197838","15274913539","15116313690","15664305559","15109282170","17308490214","15120040375","18902870809","17375757652","18874285906","13467619773","18390846290","15607317159","18163912073","18674879143","18573197997","15580882182","18673380559","15527367483","18684881117","15874903200","18708990195","18184778417","18274545191","13509649045","18684929079","13203317422","17773407310","18570336368","18229709814","19892939486","16673288476","17680649692","13787218865","19973903715","18942575573","17352851152","15200633200","14707414186","19906615906","18229937327","18569435997","15243617403","18510137237","15874147683","17752886899","18207411011","18508459329","17801076135","16680810778","13755146725","16670114553","17388958312","15574962506","13308421173","18273083622","17873264583","15243634903","13875996214","13257406889","15116324017","13575021564","15211321230","13144967682","17872728008","18229162580","17779586162","15651660268","18273383072","18073626727","15061884967","13045866116","18373412640","15973188304","15673038080","13815433968","15576372481","18569504997","15084945250","18545202719","15367754155","18153774919","15111075316","18942571088","13407451061","18182129126","18813493774","15576650931","17872131313","15073180800","15674804518","13789001885","13823790927","15874844061","13507312825","15367886328","15200868371","15573437537","15211100828","18573151480","15084958348","18508484666","17773104584","18579278939","15111103576","13973063600","18973119493","18600841771","18521706031","17640072109","15211151662","15211161182","18229994557","17775776977","19865769613","13574875868","18390800701","13657486118","15084977952","18390943799","13875806501","18607312986","13907313372","15700715832","18684777497","18173187162","15700773726","18608400072","18073031860","13007496665","13637482880","13874875446","15580822322","18374743070","13687392980","15973120202","13548672193","18674880933","18573195559","18670079767","13549689966","13973131136","17608480505","13703010351");
        StringBuffer phones = new StringBuffer();
        StringBuffer names = new StringBuffer();

        for(int i=0;i<members.size();i++){
            JSONObject member = members.getJSONObject(i);
            String telNumber = member.getStr("telNumber");
            String name = member.getStr("name");
            String seeyonId = member.getStr("id");

            phones.append("'").append(telNumber).append("',");
            names.append("('").append(telNumber).append("',").append("'").append(name).append("'),");
            /*if(phoneExt.contains(telNumber)){
                System.out.println("update wedata_company_employee_info set seeyon_id="+seeyonId+" where phone='" + telNumber+"' and name='"+name+"';");
            }*/
            if("18675411338".equals(telNumber)){
                System.out.println(member);
            }
        }
        System.out.println(phones);
        System.out.println(names);
    }



    /**
     * 修改人员信息
     */
    public static void createMember(){
        JSONObject body = new JSONObject();
        //body.set("id",-5332376560213472597L);
        body.set("orgAccountId",670869647114347L);
        body.set("orgDepartmentId", -1625854415707355017L);//部门ID
        body.set("orgLevelId", -53080824737281993L);//职务ID
        body.set("orgPostId", -6481062120812035580L);//岗位ID
        //body.set("code", dto.getId());//编号
        body.set("name", "杨林1");//姓名
        // body.set("sortId", 1);//排序号  V5.6最新版本后可以不用录入此参数
        body.set("telNumber", "18867363985");//移动电话
        body.set("gender", 1);//性别：-1为未指定、1为男、2为女
        body.set("password", "654321@aA");//密码
        body.set("loginName", "18867363985");//登录名

        JSONObject result = HttpUtils.sendRequest(token.hostUrl + "/rest/orgMember?token=" + token.getToken(),null,body,"POST");

        System.out.println(result);
    }
    /**
     * 修改人员信息
     */
    public static void updateMember(){
        JSONObject body = new JSONObject();
        body.set("id",-5332376560213472597L);
        body.set("orgAccountId",670869647114347L);
        //body.set("name","杨林");
        body.set("gender","1");

        JSONObject result = HttpUtils.sendRequest("http://36.158.17.187:8089/seeyon" + "/rest/orgMember?token=" + token.getToken(),null,body,"PUT");
        //{"successMsgs":[{"code":"SUCCESS","ent":{"orgAccountId":670869647114347,"id":5572522706523933505,"name":"杨林1","i18nNameId":null,"code":"","createTime":1713428895929,"updateTime":1713428895929,"sortId":1961,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"orgLevelId":-53080824737281993,"orgPostId":-6481062120812035580,"orgDepartmentId":-1625854415707355017,"type":1,"isInternal":true,"isLoginable":true,"isVirtual":false,"isAssigned":true,"isAdmin":false,"isValid":true,"state":1,"properties":{"birthday":"","politics":"","website":"","address":"","imageid":"","gender":1,"degree":"","postAddress":"","emailaddress":"","reporter":"","blog":"","hiredate":"","extPostLevel":"","weixin":"","weibo":"","telnumber":"18867363985","postalcode":"","eduBack":"","officenumber":"","location":"","idnum":""},"second_post":[],"concurrent_post":[],"customerAddressBooklist":[],"primaryLanguange":null,"pinyin":"yanglin1","pinyinhead":"yl1","secretLevel":null,"address":null,"location":null,"valid":true,"isAssignedStatus":1,"reporter":null,"fullName":"杨林1","telNumber":"18867363985","loginName":"18867363985","entityType":"Member","emailAddress":null,"defaultGuest":false,"idNum":null,"postAddress":null,"weixin":null,"officeNum":null,"birthday":null,"weibo":null,"degree":null,"hiredate":null,"blog":null,"visitor":false,"website":null,"gender":1,"v5External":false,"postalcode":null,"vjoinExternal":false,"guest":false,"screenGuest":false,"i18nNameWithLocale":"杨林1","dataI18nCategoryName":"organization.member.name","realSortId":1961,"preName":"","orgAccountName":"健萌体育产业发展集团有限公司","orgPostName":"JAVA组长","orgDepartmentName":"财务信息化研发组","orgLevelName":"一般管理人员"},"msgInfo":null}],"errorMsgs":[],"errorMsgInfos":[],"success":true}
        System.out.println(result);
    }

}
